const fs = require('fs');
const readline = require('readline');

const filePath = 'english_origin.txt'; // 替换成实际文件路径

// 使用readline创建行读取器
const lineReader = readline.createInterface({
  input: fs.createReadStream(filePath),
  output: process.stdout,
  terminal: false,
});

const linesMap = {}; // 存储行内容和对应的行号
let lineNumber = 0;

lineReader.on('line', (line) => {
  lineNumber++;
  // 如果行内容已经在linesMap中，则添加行号，否则创建条目
  if (linesMap.hasOwnProperty(line)) {
    linesMap[line].count++;
    linesMap[line].lineNumbers.push(lineNumber);
  } else {
    linesMap[line] = { count: 1, lineNumbers: [lineNumber] };
  }
});

lineReader.on('close', () => {
  // 遍历linesMap来找出重复行
  for (const line in linesMap) {
    if (linesMap[line].count > 1) {
      console.log(`Line: "${line}" - Count: ${linesMap[line].count}, Line Numbers: ${linesMap[line].lineNumbers.join(', ')}`);
    }
  }
});